﻿Public Class EventLogClass
    Public Shared Function WriteToEventLog(ByVal entry As String, _
                                           Optional ByVal appName As String = "ApplicationSourceName", _
                                           Optional ByVal eventType As EventLogEntryType = EventLogEntryType.Information, _
                                           Optional ByVal logName As String = "LogName", _
                                           Optional ByVal eventID As Integer = 0 _
                                            ) As Boolean

        Dim objEventLog As New EventLog
        Try
            'Register the Application as an Event Source
            If Not EventLog.SourceExists(appName) Then
                EventLog.CreateEventSource(appName, logName)
            End If

            'log the entry
            objEventLog.Source = appName
            objEventLog.WriteEntry(entry, eventType, eventID)

            Return True
        Catch Ex As Exception
            Return False
        End Try
    End Function

End Class
